package com.lv.dhart.widget.text_edit;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lv.dhart.R;


public class CustomTextEdit extends RelativeLayout {

    private TextView textView;
    private EditText editText;

    public CustomTextEdit(Context context) {
        this(context, null);
    }

    public CustomTextEdit(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomTextEdit(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.custom_text_edit, this, true);

        textView = findViewById(R.id.textView);
        editText = findViewById(R.id.editText);

        if (attrs != null) {
            TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomTextEdit);
            String left_text = typedArray.getString(R.styleable.CustomTextEdit_left_text);
            String right_text = typedArray.getString(R.styleable.CustomTextEdit_right_text);
            int left_c = typedArray.getColor(R.styleable.CustomTextEdit_left_color, getResources().getColor(R.color.orange));
            int right_c = typedArray.getColor(R.styleable.CustomTextEdit_right_color, getResources().getColor(R.color.red));


            if (left_text != null) {
                textView.setText(left_text);
            }
            if (right_text != null) {
                editText.setText(right_text);
            }
            textView.setTextColor(left_c);
            editText.setTextColor(right_c);

            typedArray.recycle();
        }
    }
    public String getText() {
        return editText.getText().toString();
    }
    public EditText getEditText() {
        return editText;
    }
}
